import { request } from "@/utils/requst"

Page({
    data: {
        pageInfo: {
            page: 1,
            size: 10
        },
        mailList: [],
        isLoad: true
    },
    onLoad() {
        this.getMail()
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom(e) {
        this.setData({
            pageInfo: {
                page: this.data.pageInfo.page+=1,
                size: 10
            }
        })
        this.getMail()
    },
    async getMail() {
        if (!this.data.isLoad){
            return
        }
        const result = await request('GET', '/sendMail/paging', this.data.pageInfo)
        const resultData:Array<any> = result.data.data
        resultData.length? '':  this.setData({isLoad: false})
        let mailList = this.data.mailList
        mailList = [...mailList, ...resultData]
        this.setData({
            mailList
        })
    },
    goWrite(){
        wx.navigateTo({url: '/pages/write/write'})
    },
})